# import torch

# d = torch.load("/home/cole/project_graduate/mmdetection/work_dirs/slot_config_attn/epoch_80.pth")
# print(d)


import numpy as np  
from scipy.spatial.distance import cdist  
  
def match_points(A, B, threshold):  
    """  
    匹配点集A和B，根据距离进行匹配，阈值设为threshold。  
    """  
    # 计算点集A和B之间的距离矩阵  
    dist_matrix = cdist(A, B)  
      
    # 找到点集A中每个点距离最近的点在点集B中的索引  
    indices = np.argmin(dist_matrix, axis=1)  
      
    # 根据索引找到点集B中每个点的匹配点在点集A中的索引  
    matches = np.argmin(dist_matrix, axis=0)[indices]  
      
    # 检查匹配是否满足阈值要求  
    valid_matches = dist_matrix[np.arange(len(A)), indices] < threshold  
    matches = matches[valid_matches]  
    indices = indices[valid_matches]  
      
    # 返回匹配结果  
    return matches, indices
  
# 示例：点的匹配问题  
points1 = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])  
points2 = np.array([[1, 1], [2, 2], [3, 3], [4, 4]])  
  
matched_rows, matched_cols = match_points(points1, points2,0.5)  
print("匹配结果：")  
print("points1: ", points1[matched_rows])  
print("points2: ", points2[matched_cols])